var statusBS= new Array();
statusBS[0]=0;
statusBS[1]=0;
statusBS[2]=0;
statusBS[3]=0;
statusBS[4]=0;
statusBS[5]=0;
statusBS[6]=0;
statusBS[7]=0;
statusBS[8]=0;
statusBS[9]=0;
function checkCode(){
	if(
		statusBS[9] == 38 && 
		statusBS[8] == 38 &&
		statusBS[7] == 40 && 
		statusBS[6] == 40 &&
		statusBS[5] == 37 &&
		statusBS[4] == 39 &&
		statusBS[3] == 37 &&
		statusBS[2] == 39 &&
		statusBS[1] == 97 &&
		statusBS[0] == 98
		){
		return true;
	}
	else{
		return false;
	}
}
function addCode(event){
	statusBS[9] = statusBS[8];
	statusBS[8] = statusBS[7];
	statusBS[7] = statusBS[6];
	statusBS[6] = statusBS[5];
	statusBS[5] = statusBS[4];
	statusBS[4] = statusBS[3];
	statusBS[3] = statusBS[2];
	statusBS[2] = statusBS[1];
	statusBS[1] = statusBS[0];
	statusBS[0] = (event.keyCode==0?event.which:event.keyCode);
}
function keyPress(event){
	addCode(event);
	if(checkCode()){
		alert("How Bob SAGET");
	}
}

// When the document is ready
$(document).ready(function(){
	$(document).keypress(keyPress);

	//Change links reference
	$("a#AFC-link").attr("href","#AFC");
	$("a#AAM-link").attr("href","#AAM");

	//Anchor scan
	$(document).hashchange( function(data){
		loadPage(location.hash.slice(1),true);
	});
	loadPage(location.hash.slice(1),false);
});

function loadPage(pageName,animation){
	switch(pageName){
		case "AFC":
			switchSmallMainMenu(pageName,animation);
			$.get('AFC.php', function(data) {
				var section = $('section');
				if(section.length>0){
					section.slideUp(1000);
					section.queue(function(){
						$(this).empty();
						$(this).dequeue();
					});
				}
				else{
					section = $(document.createElement('section'));
					$("footer").before(section);
				}

				section.slideDown(1000);
			});
			break;
		case "AAM":
			switchSmallMainMenu(pageName,animation);
		default:
			return;
	}
}

function switchSmallMainMenu(pageName,animation){
	var mainMenu = $("nav#MainMenu");
	$("nav#MainMenu li").removeAttr("class");
	$("nav#MainMenu a#"+pageName+"-link").parent().attr("class","selected");
	if(mainMenu.hasClass("FullMainMenu")){
		var a = $("nav#MainMenu a");
		var imgs = $("nav#MainMenu img");
		if(animation == true){
			mainMenu.animate({marginTop:'-=6em'},1000);
			imgs.slideUp(1000);
			a.animate({height:'29px'},1000);
		}
		mainMenu.queue(function(){
			$(this).removeAttr("style");
			$(this).attr("class","SmallMainMenu");
			$(this).dequeue();
		});
		imgs.queue(function(){
			$(this).removeAttr("style");
			$(this).dequeue();
		});
		a.queue(function(){
			$(this).removeAttr("style");
			$(this).dequeue();
		});
	}
}
